$(function(){
		
		var editor = CKEDITOR.replace('articleContent');
		$("#articleCategory").find("option[text='"  +$('#categoryName').val()+ "']" ).attr("selected",true);
		CKEDITOR.instances.articleContent.setData($("#contentStr").val());
		$('#submitFeedBack').hide();
		
		var preViewEditor =  CKEDITOR.replace('articlePreView');
		CKEDITOR.instances.articlePreView.setData($("#preViewStr").val());
		
		$("#articleSubmit").click(function(){
			 $(".formError").remove();
			 var validationResult = true;
			 $(".required").each(function(){
				if($(this).val() ==""){	 
					 $.validationEngine.buildPrompt($(this),"* This field is required","error",false);
					 setTimeout(function(){$(".formError").fadeOut(2000);},3000);
					 validationResult =false;
				} 
			 });
			 if(!validationResult){
				 return;
			 }
		   //if(!$.validationEngine.submitValidation("#articleForm")){
				var data = {"title":$("#title").val(),"articleCategoryId":$("#articleCategory").val(),"keyWords": $("#keyWords").val(),"articleSource": $("#articleSource").val(),"articleContent":CKEDITOR.instances.articleContent.getData(),"articlePreView":CKEDITOR.instances.articlePreView.getData(),"displayReadMore":$("#displayReadMore").attr("checked"),"commentOpen":$("#commentOpen").attr("checked")};
				var url = $("#url").attr("href") ;
				$.post(url,
					   data,
					   function(data){
							if(data == 'add' ){
								$("#articleCategory").find('option').get(0).selected = true;
								$("#title").val('');
								$("#keyWords").val('');
								$("#articleSource").val('');
								CKEDITOR.instances.articleContent.setData('');
								CKEDITOR.instances.articlePreView.setData('');
								$.blockUI({ message: $('#addFeedBack')  });
								setTimeout(function(){
									$.unblockUI();
								},2000);
								
								//$('#submitFeedBack').fadeIn();
								//$('#submitFeedBack').fadeOut(3000);
							}else{
								$.blockUI({ message: $('#updateFeedBack')  });
								setTimeout(function(){
									$.unblockUI();
									window.location.href='preArticleManager';
								},2000);
								
							}
				 	    },
					   'html'
				);
			//}
		});
		
		
		$("#preViewArticle").click(function(){
			$("#preArticleTitle").val($("#title").val());
			$("#preArticleCategoryId").val($("#articleCategory").val());
			$("#preKeyWords").val($("#keyWords").val());
			$("#preArticleSource").val($("#articleSource").val());
			$("#preArticleContent").val(CKEDITOR.instances.articleContent.getData());
			$("#PreArticlePreView").val(CKEDITOR.instances.articlePreView.getData());
			$("#preDisplayReadMore").val($("#displayReadMore").attr("checked"));
			$("#preCommentOpen").val($("#commentOpen").attr("checked"));
			$("#preview").submit();
		});
		
		 
	});